<?php
class GetCorpLogoWidget extends Widget{

	public function render($data){
		$thefile = "/data/corp/" .$data['corp_id']. "/logo/" . $data['size'] . '.' . fileExtName($data['logo']);
		if(is_file(SITE_PATH.$thefile)){//有要的文件
			$thefile = ".".$thefile;
		}else{
			$thefile = "/data/corp/" .$data['corp_id']. "/logo/original/".$data['logo'];
			if(is_file(SITE_PATH.$thefile)){//有原始文件
				$size = explode('x',strtolower($data['size']));
				if($size[0]<30 || $size[1]<30){
					$thefile = "./data/blank.gif";
				}else{
					require_cache("./addons/libs/Image.class.php");
					$img = new Image();
					$thumbname = "/data/corp/" .$data['corp_id']. "/logo/" . $data['size'] . '.' . fileExtName($data['logo']);
					$newimg = $img->thumb(SITE_PATH.$thefile,SITE_PATH.$thumbname,'',$size[0],$size[1]);
					if(!$newimg){
						$thefile = "./data/blank.gif";
					}else{
						$thefile = ".".$thumbname;
					}

				}
			}else{
				$thefile = "/data/".$data['size']."logo.gif";
				if(is_file(SITE_PATH.$thefile)) {
					$thefile = ".".$thefile;
				}else{
					$size = explode('x',strtolower($data['size']));
					if($size[0]<30 || $size[1]<30){
						$thefile = "./data/blank.gif";
					}else{
						$baseimage = SITE_PATH.'/data/nologo.gif';
						if(is_file($baseimage)) {
							require_cache("./addons/libs/Image.class.php");
							$img = new Image();
							$thumbname = SITE_PATH.$thefile;
							$newimg = $img->thumb($baseimage,$thumbname,'',$size[0],$size[1]);
							if(!$newimg){
								$thefile = "./data/blank.gif";
							}else{
								$thefile = "./data/".$data['size']."logo.gif";
							}
						}else{
							$thefile = "./data/blank.gif";
						}
					}
				}
			}
		}
        return $thefile;
    }

}
?>